import React from 'react';
import { Button } from 'antd';
import { toJS } from 'mobx';
import { WeaSwitch } from 'comsMobx';
import { WeaLocaleProvider, WeaFormItem, WeaSearchGroup } from 'ecCom';
import '../../../workflow/util/windowFun';// 支持openSPA4Single,doPrintRequest,showallreceived等方法
// import Forward from './Forward';
import SearchComponent from './SearchComponent';
// import TabComponent from "./TabComponent";

const getLabel = WeaLocaleProvider.getLabel;

/**
 * 公文类  列表基类
 */
class BaseListComponent extends React.Component {
  componentDidMount() {
    // const { listStore } = this.state;
    // let defaultQueryCondition = toJS(this.props.location.query);
    // listStore.buildTabs();
    // listStore.buildSearchCondition({},defaultQueryCondition);
  }

  changeTab(selectedTab) {
    const { listStore } = this.state;
    listStore.setSelectedTab(selectedTab);
    // 构建除了搜索框之外的查询参数
    let officalType = listStore.selectedTab;
    listStore.searchStore.setOtherSearchParams({ officalType });

    // listStore.doSearch();
    listStore.buildSearchCondition();
  }

  renderSearchAdForm() {
    const { listStore } = this.state;
    return (<SearchComponent ecId={`${this && this.props && this.props.ecId || ''}_SearchComponent@ax4lsq`} searchStore={listStore.searchStore} listStore={listStore} />);
  }

  renderRightAndDropMenus() {
    const { listStore } = this.state;
    const datas = [
      {
        key: '1',
        disabled: false,
        icon: <i className="icon-coms-search" />,
        content: getLabel('197', '搜索'),
        onClick: () => listStore.doSearch(),
      },
    ];
    return datas;
  }

  renderSearchAdButtons() {
    const { listStore } = this.state;
    return [
      (<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@hv518k@search`} type="primary" onClick={() => listStore.doSearch()}>{getLabel('197', '搜索')}</Button>),
      (<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@bnukvo@reset`} type="ghost" onClick={() => { listStore.resetForm(); listStore.setSearchsBaseValue(''); }}>{getLabel('2022', '重置')}</Button>),
      (<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@45jo5r@cancel`}
        type="ghost"
        onClick={() => {
          listStore.resetForm();
          listStore.searchStore.changeShowSearchAd(false);
        }}
      >{getLabel('31129', '取消')}</Button>),
    ];
  }

  render() {
    return <span />;
    // const { listStore } = this.state;
    // return (
    //     <div>
    //         <WeaRightMenu
    //             datas={this.renderRightAndDropMenus()}
    //         >
    //             <WeaTop
    //                 title={listStore.topTitle}
    //                 icon={<i className='icon-coms-official' />}
    //                 iconBgcolor={"#f14a2d"}
    //                 buttons={listStore.getTopBtns()}
    //                 showDropIcon={listStore.showDropMenu}
    //                 dropMenuDatas={this.renderRightAndDropMenus()}
    //             >
    //                 {
    //                     !listStore.showNewSearch &&
    //                     listStore.API_TABCOUNT !== "" && <WeaTab
    //                         datas={listStore.tabs}
    //                         counts={listStore.tabsCount}
    //                         keyParam={listStore.S_TAB.KEYPARAM}  //主键
    //                         countParam={listStore.S_TAB.COUNTPARAM} //数量
    //                         selectedKey={listStore.selectedTab}
    //                         onChange={selectedKey => this.changeTab(selectedKey)}
    //                     >
    //                     </WeaTab>
    //                 }

    //                 {
    //                     !listStore.showNewSearch &&
    //                     <WeaSearchPanel
    //                         searched={listStore.searchStore.searched}
    //                         inputValue={listStore.getSearchsBaseValue()}
    //                         onSearch={v => listStore.doSearch(v)}
    //                         onSearchChange={v => listStore.setSearchsBaseValue(v)}
    //                         buttonsAd={this.renderSearchAdButtons()}
    //                         searchsAd={this.renderSearchAdForm()}
    //                         visible={listStore.searchStore.showSearchAd}
    //                         onVisibleChange={v => listStore.searchStore.changeShowSearchAd(v)}
    //                         advanceHeight={360}
    //                     />
    //                 }

    //                 {
    //                     listStore.showNewSearch &&
    //                     <TabComponent
    //                         {...listStore.tabComponentParams}
    //                     />
    //                 }

    //                 <WeaTable
    //                     hasOrder={true}
    //                     needScroll={true}
    //                     comsWeaTableStore={listStore.searchStore.tableStore}
    //                     rowSelection={{
    //                         onChange: (selectedKeys, selectedRows) => {
    //                             listStore.handleSelectedRowsChange(selectedRows);
    //                         }
    //                     }}
    //                     register_table={listStore.doSearch}
    //                     getColumns={listStore.getColumns}
    //                     onOperatesClick={this.onOperatesClick}
    //                 >
    //                 </WeaTable>
    //             </WeaTop>
    //         </WeaRightMenu>
    //         {
    //             listStore.doForward &&
    //             <Forward forwardParams={listStore.forwardParams} callBackActions={null} />
    //         }
    //     </div>
    // )
  }

  onOperatesClick = (record, index, operate) => {
    const { listStore } = this.state;
    const funName = operate.href.replace(/(javascript\:)|(\(\))/g, () => '');

    if (funName === 'reqListUtil.doForward;') {
      let params = {
        requestid: record.requestid, // 1200200,
        nodeid: record.currentnodeid,
        showForward: true,
        forwardflag: '1',
        forwardOperators: '',
      };

      listStore.setForwardParams(params);// record.requestid
      listStore.setDoForward(true);
    }
    if (funName === 'reqListUtil.doPrint;') {
      doPrintRequest(record.requestid, record.creater);
    }
    if (funName === 'doReadIt;') {
      doReadRequest(record.requestid);
      // odocUtil2.doOdocReadIt(record.requestid);
    }
  }

  searchCustomRender(form, condtion) {
    let group = [];
    form.isFormInit && toJS(condtion).map((c, index) => {
      let items = [];
      c.items.map((field) => {
        let col = 2;
        items.push({
          com: (<WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@1x6ve4@${field.domkey[0]}`}
            label={`${field.label}`}
            labelCol={{ span: `${field.labelcol}` }}
            ratio1to2
            error={form.getError(field)}
            tipPosition="bottom"
            wrapperCol={{ span: `${field.fieldcol}` }}
          >
            <WeaSwitch ecId={`${this && this.props && this.props.ecId || ''}_WeaSwitch@1fvyln@${field.domkey[0]}`} fieldConfig={field} form={form} />
          </WeaFormItem>),
          col,
          hide: form.isHide(field, (keys, allParams) => {
            if (allParams.officalType == '') {
              if (field.label == '签报环节' || field.label == '收文环节' || field.label == '发文环节') return true;
            }
            if (allParams.officalType == '1') {
              if (field.label == '签报环节' || field.label == '收文环节') return true;
            }
            if (allParams.officalType == '2') {
              if (field.label == '签报环节' || field.label == '发文环节') return true;
            }
            if (allParams.officalType == '3') {
              if (field.label == '收文环节' || field.label == '发文环节') return true;
            }
            return false;
          }),
        });
      });
      group.push(<WeaSearchGroup ecId={`${this && this.props && this.props.ecId || ''}_WeaSearchGroup@v3tqb0@${index}`} needTigger={false} title={c.title} showGroup={c.defaultshow} items={items} />);
    });
    return group;
  }
}


export default BaseListComponent;

